//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows;
using System.Windows.Data;

namespace OpenLS.Chart.UI
{
    using convert = Convert;
    class ChartInfoFactory: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var result = new ChartInfo();
            int i = 0;
            result.XMinimum = toDouble(values[i++]);
            result.XMaximum = toDouble(values[i++]);
            result.YMinimum = toDouble(values[i++]);
            result.YMaximum = toDouble(values[i++]);
            result.ZMinimum = toDouble(values[i++]);
            result.ZMaximum = toDouble(values[i++]);
            return result;
        }

        private static double toDouble(object value)
        {
            if (value == DependencyProperty.UnsetValue)
                return 0;
            return convert.ToDouble(value);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
